<template>
    <div class="components-container">
        <div class="header-form">
        <div class="layui-inline">
            <label class="layui-form-label" >逝者姓名</label>
             <div class="layui-input-inline">
                <el-input v-model="selectData.RegnameLike" placeholder="请输入逝者姓名" @keydown.enter.native="btnSearch"></el-input>
             </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >编号</label>
             <div class="layui-input-inline">
                <el-input v-model="selectData.AssnameLike" placeholder="请输入骨灰堂编号" @keydown.enter.native="btnSearch"></el-input>
             </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" >结束日期</label>
             <div class="layui-input-inline">
                <el-date-picker  v-model="selectData.AshenddateGreaterAndEquals" type="date" placeholder="请选择结束日期大于等于该日期" @change="btnSearch">
                </el-date-picker>
                至
                <el-date-picker  v-model="selectData.AshenddateLessAndEquals" type="date" placeholder="请选择结束日期小于等于该日期" @change="btnSearch">
                </el-date-picker>
             </div>
        </div>
        <el-button type="primary" :disabled="downloadLoading" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
        <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
     </div>
     <div>
        <ul class="toolList">
          <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button type="primary" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
          </li>
          <li>
          <el-button type="primary" :disabled="this.$store.state.isloading" @click="exportExcel" style="margin-left:20px;margin-bottom:-10px;">导出Excel</el-button>
          </li>
        </ul>
    </div>
    <dataTable :headList="headList" :dataList="dataList" :height="height" :hiddenPageOrder="false" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
    <printmodal ref="printPdf"></printmodal>
     <!-- 详情 -->
    <sweet-modal ref="info" class="dialog">
      <h3>{{title}} </h3>
        <div style=" height:330px; margin:30px 50px">
          <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">业务编号</label>
            <div class="layui-input-inline">
              <el-input v-model="ashUseData.REGBUSNUM" placeholder="请输入业务编号" readonly></el-input>
            </div>
          </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">逝者姓名</label>
              <div class="layui-input-inline">
              <el-input v-model="ashUseData.REGNAME" readonly></el-input>
              </div>
              <label class="layui-form-label">联系人</label>
              <div class="layui-input-inline">
              <el-input v-model="ashUseData.REGHANDLERNAME" readonly></el-input>
              </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">联系电话</label>
              <div class="layui-input-inline">
              <el-input v-model="ashUseData.REGHANDLERLINK" readonly></el-input>
              </div>
              <label class="layui-form-label">备注</label>
              <div class="layui-input-inline">
              <el-input  v-model="ashUseData.REGREMARK" readonly></el-input>
              </div>
            </div>
        </div>

        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">骨灰堂</label>
            <div class="layui-input-inline">
             <el-input  v-model="ashUseData.ASSNO" readonly></el-input>
            </div>
          </div>
          <div class="layui-inline">
              <label class="layui-form-label">寄存卡号</label>
              <div class="layui-input-inline">
                 <el-input  v-model="ashUseData.ASHNUMBER" readonly></el-input>
              </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">开始日期</label>
              <div class="layui-input-inline">
                <el-input  v-model="ashUseData.ASHBEGDATE"  readonly></el-input>
              </div>
            </div>
             <div class="layui-inline">
              <label class="layui-form-label">结束日期</label>
              <div class="layui-input-inline">
                 <el-input  v-model="ashUseData.ASHENDDATE" readonly></el-input>
              </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
              <label class="layui-form-label">备注</label>
              <div class="layui-input-inline">
                 <el-input  type="textarea" v-model="ashUseData.ASHREMARKS" readonly></el-input>
              </div>
            </div>
        </div>
      </div>
      <div class="layui-form-item btnCenter">
          <el-button @click="infoClose">取消</el-button>
      </div>
    </sweet-modal>
    </div>
</template>

<style  rel="stylesheet/scss" lang="scss" scoped>

</style>
<script>
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import printmodal from "@/components/Pdf/Print";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import sweetModal from "@/components/sweetModal";
import { PRINT } from "@/components/Pdf/PDF.js";
import { manage } from "@/mixins/managePage.js";
const INFO = "详情";
const EXPORT = "导出";
export default {
  name: "depositmaturitySearch",
  mixins: [manage],
  data() {
    return {
      pageWidth: 1100,
      maxHeight: 500,
      ashUseData: {},
      selectData: {
        AssnameLike: null,
        RegnameLike: null,
        AshenddateGreaterAndEquals: null,
        AshenddateLessAndEquals: new Date()
      },
      height: "620",
      downloadLoading:false
    };
  },
  methods: {
    exportExcel() {
      var startTime;
      var endTime;
      if(this.selectData.AshenddateGreaterAndEquals){
         startTime = this.selectData.AshenddateGreaterAndEquals.toLocaleDateString();
      }else{
        startTime = '空';
      }
      if(this.selectData.AshenddateLessAndEquals){
        endTime = this.selectData.AshenddateLessAndEquals.toLocaleDateString();
      }else{
        endTime = '空';
      }
      var header = '寄存到期查询' + '(' + startTime + '--' + endTime + ')';
       if (this.dataList.length === 0){
          this.$message.error("无导出数据！");
          return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.dataList, header);
        this.downloadLoading = false;
      });
    },
    operate(order) {
      this.order = order;
      switch (this.order) {
        case INFO:
          this.title = "寄存到期详情";
          this.dataInfo();
          break;
        case EXPORT:
          this.$refs.printPdf.report(PRINT.PDFDEPOSITMATURITYSEARCH, this.getDataC());
          break;
        default:
      }
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetBeoverdueColumns,
        res => {
          this.headList = res.data.content;
          console.log(this.headList);
        }
      );
    },
    getDataC() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      Data.AshenddateGreaterAndEquals = formatDate(
        Data.AshenddateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.AshenddateLessAndEquals = formatDate(
        Data.AshenddateLessAndEquals,
        "yyyyMMdd"
      );
      let data = {
        PageIndex: 1,
        PageSize: 1000,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      return data;
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      Data.AshenddateGreaterAndEquals = formatDate(
        Data.AshenddateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.AshenddateLessAndEquals = formatDate(
        Data.AshenddateLessAndEquals,
        "yyyyMMdd"
      );
      let data = {
        PageIndex: 1,
        PageSize: 1000,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Search.QueryBeoverdue,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    dataInfo() {
      var data = {
        ASHID: this.currentRow.ASHID
      };
      apiBase.DoService(data, apiBase.getApiAdress().AshesUse.Detail, res => {
        this.ashUseData = res.data.content;
        //this.ashUseData.ASHID = this.currentRow.ASHID;
        this.$refs.info.open();
      });
    },
    btnShow(btn) {
      switch (btn) {
        case "导出":
          return true;
          break;
        default:
          return false;
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        AssnameLike: null,
        RegnameLike: null,
        AshenddateGreaterAndEquals: null,
        AshenddateLessAndEquals: null
      };
      this.selectData.AshenddateGreaterAndEquals = new Date();
      this.selectData.AshenddateGreaterAndEquals.setDate(1);
      this.selectData.AshenddateLessAndEquals = new Date();
      var day = new Date();
      var year = day.getFullYear();
      var month = day.getMonth() + 1;
      var d = new Date(year, month, 0);
      var dat = d.getDate();
      this.selectData.AshenddateLessAndEquals.setDate(dat);
      this.getData();
    }
  },
  created() {
    this.selectData.AshenddateGreaterAndEquals = new Date();
    this.selectData.AshenddateGreaterAndEquals.setDate(1);
    this.selectData.AshenddateLessAndEquals = new Date();
    var day = new Date();
    var year = day.getFullYear();
    var month = day.getMonth() + 1;
    var d = new Date(year, month, 0);
    var dat = d.getDate();
    this.selectData.AshenddateLessAndEquals.setDate(dat);
    this.getColumns();
    this.getData();
  },
  components: {
    dataTable,
    sweetModal,
    printmodal
  }
};
</script>

